package com.example.administrator.recyclerviewtestdata321lz.activity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.administrator.recyclerviewtestdata321lz.R;
import com.example.administrator.recyclerviewtestdata321lz.adapter.MyAdapter;
import com.example.administrator.recyclerviewtestdata321lz.bean.TcaseBean;
import com.example.administrator.recyclerviewtestdata321lz.iface.TcaseListener;
import com.example.administrator.recyclerviewtestdata321lz.model.Tcasemodel;

import java.util.List;


public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;//显示布局效果
    private MyAdapter myAdapter;//适配器
    private List<TcaseBean> list=null;//数据源
    TcaseListener tcaseListener = new TcaseListener() {
        @Override
        public void onReaponse(List<TcaseBean> beanlist) {
            list=beanlist;
            myAdapter.setList(list);
            myAdapter.notifyDataSetChanged();
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(MainActivity.this,msg,Toast.LENGTH_SHORT).show();
        }
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initRecyclerView();
        //实例化model
        Tcasemodel tcasemodel = new Tcasemodel();
        tcasemodel.getResultList("article",2,"k17vmm42ui9al6clh0lo3de2t7", tcaseListener);
    }

    private void initRecyclerView() {
        //获取RecyclerView,设置属性，获取数据源，绑定
        recyclerView=(RecyclerView)findViewById(R.id.recyclerview);
        //创建默认的线性布局
        layoutManager= new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        //list=getData();
        myAdapter=new MyAdapter(this);
        myAdapter.setList(list);

        recyclerView.setAdapter(myAdapter);
    }
}
